using System.Reflection;
using Bosphorus.Library.Facade.Core.Facade.Base;
using Bosphorus.Library.Facade.Loader.Castle.Configurator;
using NExt.Serialization.Core;

namespace NExt.Serialization
{
    public class JsonSerializer : InternalLoadedFacadeBase<JsonSerializer, CompileTimeFacadeLoader>
    {
        private static IJsonSerializer jsonSerializer;

        public static string Serialize(object instance)
        {
            return jsonSerializer.Serialize(instance);
        }

        public static T Deserialize<T>(string json)
        {
            return jsonSerializer.Deserialize<T>(json);
        }

        public static object Deserialize(string json, System.Type type)
        {
            return jsonSerializer.Deserialize(json, type);
        }

        public static void Load(string assemblyName)
        {
            Loader.LoadAssembly(Assembly.Load(assemblyName));
            jsonSerializer = (IJsonSerializer)Container.Resolve(typeof(IJsonSerializer));
        }
    }
}